package com.dyz.model;

import com.dyz.contant.Constants;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;
@Data
@AllArgsConstructor
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    //成功
    public static final Integer SUCCESS = Constants.SUCCESS;
    //失败
    public static final Integer FAIL = Constants.FAIL;
    //状态码
    private Integer code;
    //提示信息
    private String msg;
    //数据
    private T data;

    public static <T> Result<T> success() {
        return new Result<T>(null, SUCCESS, null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(data, SUCCESS, null);
    }

    public static <T> Result<T> success(T data, String msg) {
        return new Result<T>(data, SUCCESS, msg);
    }

    public static <T> Result<T> fail() {
        return new Result<T>(null, FAIL, null);
    }

    public static <T> Result<T> fail(T data) {
        return new Result<T>(data, FAIL, null);
    }

    public static <T> Result<T> fail(T data, String msg) {
        return new Result<T>(data, FAIL, msg);
    }

    public static <T> Result<T> fail(String msg) {
        return new Result<T>(null, FAIL, msg);
    }

    public Result(T data, Integer code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
